<template>
    <div class="menu-card">
        <slot></slot>
        <div class="question-label">
            <div class="label-title">答题卡</div>

            <div class="label-type">
                <div class="label-summary">
                    <div class="label-summary__item" v-for="(item, index) in cardList" :key="index" :class="item.class">
                        <span class="flag"> </span>
                        <span class="text"> {{ item.text }}</span>
                    </div>
                </div>


                <div class="label-items">
                    <div class="label-item—key" v-for="(item, index) in  datas " :key="index" @click="itemClick(index)"
                        :class="setClass(item, index)">
                        <span> {{ index + 1 }}</span>
                    </div>
                </div>



            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: ['datas', 'userAnswers', "type", "activeIndex"],


    computed: {
        cardList() {
            if (this.type === 'process') {
                return [{
                    text: "已做",
                    class: "process"
                }, {
                    text: "未答",
                    class: "empty"
                }]
            } else if (this.type === "result") {
                return [{
                    text: "答对",
                    class: "success"
                }, {
                    text: "答错",
                    class: "error"
                }, {
                    text: "未作答",
                    class: "empty"
                }]
            }
        }
    },

    methods: {

        setClass(item, index) {
            if (this.type === 'process') {
                return {
                    "process": this.getUserAnswer(index),
                    "active": this.activeIndex == index
                }
            }

            if (this.type === 'result') {
                return {
                    [item.status]: true,
                }
            }
        },


        getUserAnswer(index) {
            if (Array.isArray(this.userAnswers[index])) {
                return this.userAnswers[index].length > 1
            } else {
                return this.userAnswers[index]
            }
        },

        itemClick(index) {
            this.activeIndex = index;
            this.$emit("itemClick", index);
        }
    }
}
</script>

<style lang="less" scoped>
.menu-card {
    background-color: #fff;
    height: 100%;
}

.question-label {
    display: flex;
    flex-direction: column;
    padding-left: 16px;
    padding-right: 16px;

    .label-title {
        padding-right: 13px;
        padding-left: 13px;
        padding-top: 10px;
        padding-bottom: 10px;
        font-family: PingFangSC, PingFang SC;
        font-size: 16px;
        color: #333333;
        line-height: 22px;
        font-style: normal;
        border-bottom: 1px solid #EFEFEF;
        user-select: none;
    }

    .label-summary {
        padding-top: 20px;
        padding-bottom: 20px;
        display: flex;
        flex-direction: row;

        .label-summary__item {
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: default;
            margin-right: 14px;
            user-select: none;
            cursor: default;

            .flag {
                width: 14px;
                height: 14px;
                border-radius: 2px;
                margin-right: 4px;
                display: inline-flex;
            }

            .text {
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 12px;
                color: #AEAEAE;
                line-height: 17px;
                text-align: center;
                font-style: normal;
            }

            &.process {
                .flag {
                    background: #F5B95C;
                }
            }

            &.empty {
                .flag {
                    border: 1px solid #D8D8D8;
                }
            }

            &.success {
                .flag {
                    background: #3560AB;
                }
            }

            &.error {
                .flag {
                    background: #FF3E11;
                }
            }

            &.active {

                .flag {
                    background: #3560AB;
                }
            }





        }
    }

    .label-items {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .label-item—key {
        cursor: pointer;
        user-select: none;
        width: 20%;
        display: flex;
        justify-content: center;
        align-items: center;

        span {
            display: inline-flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
            margin-right: 20px;
            width: 22px;
            height: 22px;
            font-size: 12px;
            border-radius: 2px;
            border: 1px solid #D8D8D8;
            line-height: 1;
        }


        &.process {
            span {
                background: #F5B95C;
                color: #fff;
                border: 1px solid transparent;
            }
        }

        &.active {
            span {
                background: #3560AB;
                color: #fff;
                border: 1px solid transparent;
            }
        }

        &.success {
            span {
                background: #3560AB;
                color: #fff;
                border: 1px solid transparent;

            }
        }

        &.error {
            span {
                background: #FF3E11;
                color: #fff;
                border: 1px solid transparent;
            }
        }
    }
}
</style>